package dataflowScheme.diagram.customs;

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.PolygonDecoration;
import org.eclipse.draw2d.RotatableDecoration;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.Transform;

/**
 * source decoration of a wire (little square)
 * 
 * @author <a href="mailto:misiak7@gmail.com">Michal Antolik</a>
 *
 */
public class SourceDecoration extends PolygonDecoration implements RotatableDecoration {

	PointList points = new PointList();
	
	private Transform transform2 = null;
	private Point location = new Point();
	
	public SourceDecoration() {
		super();
	}
	
	@Override
	protected void fillShape(Graphics graphics) {
		super.fillShape(graphics);
	}

	@Override
	protected void outlineShape(Graphics graphics) {
		super.outlineShape(graphics);
	}

	@Override
	public void setLocation(Point p) {
		points = null;
		bounds = null;
		location.setLocation(p);
		getTransform().setTranslation(p.x, p.y);
	}
	
	@Override
	public void setReferencePoint(Point ref) {
	}
	
	@Override
	public PointList getPoints() {
		if (points == null) {
			points = new PointList();

			points.addPoint(getTransform().getTransformed(new Point(-2,-2)));
			points.addPoint(getTransform().getTransformed(new Point(2,-2)));
			points.addPoint(getTransform().getTransformed(new Point(2,2)));
			points.addPoint(getTransform().getTransformed(new Point(-2,2)));
			
		}
		return points;
	}
	
	private Transform getTransform(){
		if(transform2 == null){
			transform2 = new Transform();
		}
		return transform2;
	}

}
